package com.ziyun.pop.web.modules.quoteFastPrint.controller;

import com.utility.New;
import com.utility.http.HttpUtils;
import com.ziyun.pop.common.utils.JsonUtils;
import com.ziyun.pop.common.utils.UserUtils;
import com.ziyun.pop.modules.quoteFastPrint.vo.QuoteFastPrintEntityVo;
import io.renren.common.annotation.SysLog;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import java.util.Map;


/**
 * 快印印刷机配置表
 *
 * @author llc
 * @email 
 * @date 2018-09-18 16:44:20
 */
@RestController
@RequestMapping("quoteFastPrint/quoteprintfactory")
public class QuoteFastPrintController {
    @Value("${erpApi}")
    private String erpApi ;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("quoteFastPrint:quoteprintfactory:list")
    public R list(@RequestParam Map<String, Object> params){
        //根据用户得到merchaint_id
        params.put("factory_id",UserUtils.getCurentUser().getSellerId());
        //封装数码快印参数
        params.put("print_type","shumakuaiyin");
        // 远程调用
        String url = erpApi + "/quoteFastPrint/quoteprintfactory/list";
        Map<String, Object> paramHeaderMap = New.hashMap();
        Map<String, Object> paramBodyMap = New.hashMap();
        paramBodyMap.put("params", params);
        // 快印机器远程调用
        String response = HttpUtils.doPost(url, paramHeaderMap, JsonUtils.map2String(paramBodyMap));
        R rs = JsonUtils.string2Object(response, R.class);
        return rs;
    }




    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("quoteFastPrint:quoteprintfactory:info")
    public R info(@PathVariable("id") Integer id){
        // 远程调用
        String url = erpApi + "/quoteFastPrint/quoteprintfactory/info";
        Map<String, Object> paramHeaderMap = New.hashMap();
        Map<String, Object> paramBodyMap = New.hashMap();
        paramBodyMap.put("id", id);
        // 快印机器远程调用
        String response = HttpUtils.doPost(url, paramHeaderMap, JsonUtils.map2String(paramBodyMap));
        R rs = JsonUtils.string2Object(response, R.class);
        return rs;
    }

    /**
     *  *修改
     */
    @SysLog("修改工厂印刷机")
    @RequestMapping("/updateWithPrice")
   /* @RequiresPermissions("quoteFastPrint:quoteprintfactory:update")*/
    public R update(@RequestBody QuoteFastPrintEntityVo quoteFastPrintEntityVo){
        ValidatorUtils.validateEntity(quoteFastPrintEntityVo.getQuoteFastPrint());
        // 远程调用
        String url = erpApi+ "/quoteFastPrint/quoteprintfactory/updateWithPrice";
        Map<String, Object> paramHeaderMap = New.hashMap();
        Map<String, Object> paramBodyMap = New.hashMap();
        paramBodyMap.put("createUser",UserUtils.getCurentUser().getUsername());
        paramBodyMap.put("quoteFastPrintEntityVo", quoteFastPrintEntityVo);
        // 快印机器远程调用
        String response = HttpUtils.doPost(url, paramHeaderMap, JsonUtils.map2String(paramBodyMap));
        R rs = JsonUtils.string2Object(response, R.class);
        return rs;
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @SysLog("删除工厂印刷机")
   /* @RequiresPermissions("quoteFastPrint:quoteprintfactory:delete")*/
    public R delete(@RequestBody Integer[] ids){
        // 远程调用
        String url = erpApi + "/quoteFastPrint/quoteprintfactory/delete";
        Map<String, Object> paramHeaderMap = New.hashMap();
        Map<String, Object> paramBodyMap = New.hashMap();
        paramBodyMap.put("update_user",UserUtils.getCurentUser().getUsername());
        paramBodyMap.put("ids", ids);
        // 快印机器远程调用
        String response = HttpUtils.doPost(url, paramHeaderMap, JsonUtils.map2String(paramBodyMap));
        R rs = JsonUtils.string2Object(response, R.class);
        return rs;
    }
    /*
    * 保存
     */
    @SysLog("保存工厂印刷机")
    @RequestMapping("/saveWithPrice")
    /*@RequiresPermissions("quoteFastPrint:quoteprintfactory:save")*/
    public R save(@RequestBody QuoteFastPrintEntityVo quotePrintFactoryVo){
        // 远程调用
        String url = erpApi + "/quoteFastPrint/quoteprintfactory/saveWithPrice";
        Map<String, Object> paramHeaderMap = New.hashMap();
        Map<String, Object> paramBodyMap = New.hashMap();
        paramBodyMap.put("create_user",UserUtils.getCurentUser().getUsername());
        paramBodyMap.put("quotePrintFactoryVo", quotePrintFactoryVo);
        paramBodyMap.put("factoryId",UserUtils.getCurentUser().getSellerId());
        // 快印机器远程调用
        String response = HttpUtils.doPost(url, paramHeaderMap, JsonUtils.map2String(paramBodyMap));
         R rs = JsonUtils.string2Object(response, R.class);
        return rs;
    }
    /**
     * 修改是否前端显示
     */
    @RequestMapping("/updateDisplay/{id}")
   /* @RequiresPermissions("quoteFastPrint:quoteprintfactory:info")*/
    public R updateDisplay(@PathVariable("id") Integer id){
        // 远程调用
        String url = erpApi + "/quoteFastPrint/quoteprintfactory/updateDisplay";
        Map<String, Object> paramHeaderMap = New.hashMap();
        Map<String, Object> paramBodyMap = New.hashMap();
        paramBodyMap.put("update_user",UserUtils.getCurentUser().getUsername());
        paramBodyMap.put("id", id);
        // 快印机器远程调用
        String response = HttpUtils.doPost(url, paramHeaderMap, JsonUtils.map2String(paramBodyMap));
        R rs = JsonUtils.string2Object(response, R.class);
        return rs;
    }
}
